package laya.util;

public class ProductCode4B extends ProductCode
{
	public ProductCode4B()
	{
		PRODUCTID_MASK		= 0x00000000ff000000l;
		VERSION_MASK		= 0x0000000000f00000l;
		VERSUFF_MASK		= 0x00000000000f0000l;
		BUILDNO_MASK		= 0x000000000000ff00l;
		RELEASENO_MASK		= 0x00000000000000f0l;
		CHECKCODE_MASK		= 0x000000000000000fl;
		COMPARE_MASK		= ~(0 | CHECKCODE_MASK);
	}
	
	public long getCode()
	{
		return 
			((m_nProductID 		& 0x000000ffl) << (4 * 6))
			| ((m_nVersion		& 0x0000000fl) << (4 * 5))
			| ((m_nVerSuff		& 0x0000000fl) << (4 * 4))
			| ((m_nBuildNo		& 0x000000ffl) << (4 * 2))
			| ((m_nReleaseType	& 0x0000000fl) << (4 * 1))
			| ((m_nCheckCode	& 0x0000000fl) << (4 * 0));
	}
	public void setCode(long code)
	{
		m_nProductID	= (code >> (4 * 6)) & 0x000000ffl;
		m_nVersion		= (code >> (4 * 5)) & 0x0000000fl;
		m_nVerSuff		= (code >> (4 * 4)) & 0x0000000fl;
		m_nBuildNo		= (code >> (4 * 2)) & 0x000000ffl;
		m_nReleaseType	= (code >> (4 * 1)) & 0x0000000fl;
		m_nCheckCode	= (code >> (4 * 0)) & 0x0000000fl;
	}

	public long makeCheckCode()
	{
		return ( m_nProductID 
				 + m_nVersion 
				 + m_nVerSuff 
				 + m_nBuildNo
				 + m_nReleaseType
			   ) & CHECKCODE_MASK;
	}

	public String toHexString(long n)
	{
		String result = "";
		String pre = Long.toHexString(n);
		
		result += getSubCode(pre, 6, 7);
		result += '-' + getSubCode(pre, 5, 5);
		result += '-' + getSubCode(pre, 4, 4);
		result += '-' + getSubCode(pre, 2, 3);
		result += '-' + getSubCode(pre, 1, 1);
		result += '-' + getSubCode(pre, 0, 0);
		
		return result;
	}
}